<template>
  <el-dialog
    draggable
    overflow
    :title="title"
    v-model="visible"
    :width="1000"
    destroy-on-close
    @closed="$emit('closed')"
  >
    {{ code }}
    <sc-VxeTable
      :tablecode="'qa_parameter_testing_save'"
      :data="form.details"
      :gridOps="gridSubOpts"
      :gridEvts="gridEvts"
      ref="subbe"
    >
    </sc-VxeTable>
    <!-- </sc-water-mark> -->
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import skDicSelect from "@/components/skDicSelect";
import skAutoChoose from "@/components/skAutoChoose";
// import XEUtils from "xe-utils";
export default {
  emits: ["success", "closed"],
  components: { skAutoChoose, skDicSelect },
  data() {
    return {
      form: {
        details: [],
      },
      title: "新增/修改",
      gridSubOpts: {
        height: 350,
        // v["xtype"] = v.type;
        //       val[k]["editRender"] = {
        //         name: "EditRender",
        //         attrs: v,
        //         autofocus: "input",
        //       };
        // columns: [
        //   {
        //     field: "value1_name",
        //     editable: true,
        //     type: ({ row }) => {
        //       return row.type;
        //     },
        //     editkey: ({ row }) => {
        //       return row.editkey;
        //     },
        //     filterfield: "value1",
        //   },
        //   {
        //     field: "value2_name",
        //     editable: true,
        //     type: ({ row }) => {
        //       return row.type;
        //     },
        //     editkey: ({ row }) => {
        //       return row.editkey;
        //     },
        //     filterfield: "value2",
        //   },
        //   {
        //     field: "value3_name",
        //     editable: true,
        //     type: ({ row }) => {
        //       return row.type;
        //     },
        //     editkey: ({ row }) => {
        //       return row.editkey;
        //     },
        //     filterfield: "value3",
        //   },
        // ],
      },
      gridEvts: {},
      rules: {},
      visible: false,
      isSaveing: false,
    };
  },

  mounted() {},
  methods: {
    open() {
      this.visible = true;
      return this;
    },
    //表单提交方法
    async submit() {
      this.isSaveing = true;
      var res = await this.$API.pro.OpenCard.parameterTestingSave.post(this.form);
      this.isSaveing = false;
      if (res.code == 200) {
        this.visible = false;
        this.$message.success("操作成功");
        this.$emit("success");
      }
    },
    getremoteDetails(data) {
      this.$API.pro.OpenCard.parameterTestingList
        .post({ filter: [{ open_card_id: data.id }], order: "id", sort: "asc" })
        .then(v => {
          if (v.data.rows.length == 0) {
            this.form.details = [
              {
                id: "row1",
                name: "成品门幅",
                need_value: data.width,
                open_card_id: data.id,
                value1: null,
                value2: null,
                value3: null,
                status_id: null,
                remark: "",
                testor_id: null,
                tested_at: null,
              },
              {
                id: "row2",
                name: "成品克重",
                need_value: data.weight,
                open_card_id: data.id,
                value1: null,
                value2: null,
                value3: null,
                status_id: null,
                remark: "",
                testor_id: null,
                tested_at: null,
              },
              {
                id: "row3",
                name: "透湿指标",
                need_value: data.soak,
                open_card_id: data.id,
                value1: null,
                value2: null,
                value3: null,
                status_id: null,
                remark: "",
                testor_id: null,
                tested_at: null,
              },
              {
                id: "row4",
                name: "水压指标",
                need_value: data.water_pressure,
                open_card_id: data.id,
                value1: null,
                value2: null,
                value3: null,
                status_id: null,
                remark: "",
                testor_id: null,
                tested_at: null,
              },
              {
                id: "row5",
                name: "剥离指标",
                need_value: data.strip_index?.name,
                open_card_id: data.id,
                value1: null,
                value2: null,
                value3: null,
                status_id: null,
                remark: "",
                testor_id: null,
                tested_at: null,
              },
              {
                id: "row6",
                name: "水洗外观",
                need_value: data.washed_index?.name,
                open_card_id: data.id,
                value1: null,
                value2: null,
                value3: null,
                status_id: null,
                remark: "",
                testor_id: null,
                tested_at: null,
              },
            ];
          } else {
            this.form.details = v.data.rows;
          }
        });
    },
    //表单注入数据
    setData(data) {
      this.form.open_card_id = data.id;
      this.title += `[${data.code}]`;
      this.getremoteDetails(data);

      return this;
    },
    setCode(code) {
      this.$API.pro.OpenCard.details.get({ code: code }).then(v => {
        this.title += `[${code}]`;
        if (v.data.rows.length > 0) this.getremoteDetails(v.data.rows[0]);
        else {
          this.$message.success(code + "此单号不存在！");
        }
      });
    },
  },
};
</script>
